package com.fallsvc.dayproblem.demo202511;

import java.util.Stack;

/**
 * @auther falls_vc
 * description:
 * @date 2025/11/9  19:11
 */
public class Demo20251109 {
    public static void main(String[] args) {
        String s = "slef";
//        for (char ch : s) {
//
//        }
    }

    // https://leetcode.cn/problems/valid-parentheses/
    // 括号匹配
    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        for(char ch : s.toCharArray()) {
            if(isLeft(ch)) {
                stack.push(ch);
            }else{
                if(stack.empty() || !match(stack.pop(),ch)) return false;
            }
        }
        return stack.empty() ? true : false;
    }
    public boolean isLeft(char ch) {
        return '(' == ch || '[' == ch || '{' == ch;
    }
//    public boolean isRight(char ch) {
//        return ')' == ch || ']' == ch || '}' == ch;
//    }
    public boolean match(char x,char y) {
        return ('(' == x)&&(')' == y) ||
                ('[' == x)&&(']' == y) ||
                ('{' == x)&&('}' == y);
    }
}
